<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <%@ include file="../../static/_head.jsp"%>

    <title>公告管理</title>
</head>
<body>

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 资讯管理
    <span class="c-gray en">&gt;</span> 公告管理
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">
    <div class="text-c">
        <span class="select-box inline">
		<select name="" class="select">
			<option value="0">全部分类</option>
			<option value="1">顶部公告</option>
			<option value="2">通知公告</option>
		</select>
		</span>
        日期范围：
        <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" class="input-text Wdate" style="width:120px;">
        -
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" class="input-text Wdate" style="width:120px;">

        <input type="text" name="" id="" placeholder="公告标题" style="width:250px" class="input-text">
        <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 开始搜索</button>
    </div>

    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:void(0)" onclick="datadel_all()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            <a href="javascript:void(0);" onclick="notice_add('新增公告','/information/notice/add','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增公告</a>
        </span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
            <thead>
            <tr class="text-c">
                <th><input type="checkbox"></th>
                <th>序号</th>
                <th>状态</th>
                <th>类型</th>
                <th>标题</th>
                <th>内容</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageInfo.list}" var="notice" varStatus="nindex">
                <tr class="text-c">
                    <td><input type="checkbox" value="${notice.id}|${notice.title}" name="isCkeckbox">
                    </td>
                    <td>${nindex.index+1}</td>
                    <td>
                        <c:if test="${notice.state==1}">
                            <span class="label label-success radius">已启用</span>
                        </c:if>
                        <c:if test="${notice.state==0}">
                            <span class="label label-warning radius">已禁用</span>
                        </c:if>
                    </td>
                    <c:if test="${notice.type==1}">
                        <td class="c-green">
                        顶部公告
                        </td>
                    </c:if>
                    <c:if test="${notice.type==2}">
                        <td class="c-blue">
                            通知公告
                        </td>
                    </c:if>
                    <td>${notice.title}</td>
                    <td>
                        <c:if test="${fn:length(notice.context)>15}">
                            ${fn:substring(notice.context, 0, 15)} ...
                        </c:if>
                        <c:if test="${fn:length(notice.context)<=15}">
                            ${notice.context}
                        </c:if>
                    </td>
                    <td><fmt:formatDate value="${notice.createTime}" pattern="yyyy-MM-dd"/></td>
                    <td class="f-14 td-manage">
                        <a style="text-decoration:none" href="javascript:void(0);" onclick="notice_edit('${notice.id}','预览','/information/notice/update','','510','N')" class="ml-5" title="预览"><i class="Hui-iconfont">&#xe616;</i></a>
                        <a style="text-decoration:none" href="javascript:void(0);" onclick="notice_delete('${notice.id}|${notice.title}')" class="ml-5" title="删除"><i class="Hui-iconfont">&#xe609;</i></a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <input type="hidden" name="total" id="total" value="${pageInfo.total}">
        <input type="hidden" name="pageNum" id="pageNum" value="${pageInfo.pageNum}">
        <input type="hidden" name="pages" id="pages" value="${pageInfo.pages}">
        <div id="kkpager"></div>
    </div>
</div>
</div>
</div>
<%@ include file="../../static/_footer.jsp" %>
<script>
    /*添加导航*/
    function notice_add(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    /*删除选中*/
    function datadel_all() {
        var chk_id = [], chk_name = [];

        $('input[name="isCkeckbox"]:checked').each(function () {
            var temp = $(this).val().split("|");
            chk_id.push(temp[0]);
            chk_name.push(temp[1]);
        });

        if (chk_id.length == 0) {
            layer.msg("没有选中的数据");
        } else {
            layer.confirm('是否删除名称为【' + chk_name + "】的数据", {
                btn: ['确定', '取消']
            }, function () {
                $.ajax({
                    url: "/information/notice/delete",
                    method: "POST",
                    data: "chkids=" + chk_id,
                    success: function (data) {
                        if (data.code == 200) {
                            layer.msg("删除成功", function () {
                                var pageNum = $("*[ name='pageNum']").val()
                                refresh(pageNum);
                            })
                        } else {
                            layer.msg("删除失败", function () {
                                var pageNum = $("*[ name='pageNum']").val()
                                refresh(pageNum);
                            })
                        }
                    }
                });
            });
        }
    }

    /*查询*/
    function selectBtn(url) {
        var pageNum = $("*[ name='pageNum']").val()
        refresh(pageNum);
    }


    /*编辑当前数据*/
    function notice_edit(id, title, url, w, h,isEdit) {
        layer_show(title, url+"?id="+id+"&type="+isEdit, w, h);
    }

    /*删除当前数据*/
    function notice_delete(data) {
        var temp = data.split("|");
        layer.confirm('是否删除名称为【' + temp[1] + "】的数据", {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: "/information/notice/delete",
                method: "POST",
                data: "chkids=" + temp[0],
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg("删除成功", function () {
                            var pageNum = $("*[ name='pageNum']").val()
                            refresh(pageNum);
                        })
                    } else {
                        layer.msg("删除失败", function () {
                            var pageNum = $("*[ name='pageNum']").val()
                            refresh(pageNum);
                        })
                    }
                }
            });
        });
    }

    /*分页插件*/
    $(function () {
        var totalPage = $("*[ name='pages']").val();
        var totalRecords = $("*[ name='total']").val();
        var pageNo = $("*[ name='pageNum']").val();
        kkpager.generPageHtml({
            pno: pageNo,
            total: totalPage,
            totalRecords: totalRecords,
            mode: 'click',
            click: function (next) {
                refresh(next);
                return false;
            }
        });
    });

    /*刷新页面*/
    function refresh(pageNum) {
        var state = $("*[ name='state']").val(), name = $("*[ name='name']").val();
        console.log(state);
        var params = "?1=1";
        if (name!=undefined && name!=""){
            params += "&name="+name;
        }
        if (state != undefined && state!="") {
            params += "&state=" + state;
        }
        return location.href = "/information/notice/index" + params + "&pageNum=" + pageNum;
    }
</script>
</body>
</html>